package org.farng.mp3.id3;

import org.farng.mp3.InvalidTagException;
import org.farng.mp3.object.ObjectLyrics3Line;
import org.farng.mp3.object.ObjectNumberHashMap;
import org.farng.mp3.object.ObjectStringHashMap;
import org.farng.mp3.object.ObjectStringNullTerminated;
import org.farng.mp3.object.ObjectStringSizeTerminated;

import java.io.IOException;


/**
 * Title: Description: Copyright:    Copyright (c) 2002 Company:
 *
 * @author Eric Farng
 * @version $Revision: 1.3 $
 */
public class FrameBodyUSLT extends AbstractID3v2FrameBody {
    /**
     * Creates a new FrameBodyUSLT object.
     */
    public FrameBodyUSLT() {
        //        setObject("Text Encoding", new Byte((byte) 0));
        //        setObject("Language", "");
        //        setObject("Description", "");
        //        setObject("Lyrics/Text", "");
    }

    public FrameBodyUSLT(FrameBodyUSLT body) {
        super(body);
    }

    /**
     * Creates a new FrameBodyUSLT object.
     *
     * @param textEncoding DOCUMENT ME!
     * @param language DOCUMENT ME!
     * @param description DOCUMENT ME!
     * @param text DOCUMENT ME!
     */
    public FrameBodyUSLT(byte textEncoding, String language, String description, String text) {
        setObject("Text Encoding", new Byte(textEncoding));
        setObject("Language", language);
        setObject("Description", description);
        setObject("Lyrics/Text", text);
    }

    /**
     * Creates a new FrameBodyUSLT object.
     *
     * @param file DOCUMENT ME!
     *
     * @throws IOException DOCUMENT ME!
     * @throws InvalidTagException DOCUMENT ME!
     */
    public FrameBodyUSLT(java.io.RandomAccessFile file)
                  throws IOException, InvalidTagException {
        this.read(file);
    }

    /**
     * DOCUMENT ME!
     *
     * @param description DOCUMENT ME!
     */
    public void setDescription(String description) {
        setObject("Description", description);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getDescription() {
        return (String) getObject("Description");
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getIdentifier() {
        return "USLT" + ((char) 0) + getLanguage() + ((char) 0) + getDescription();
    }

    /**
     * DOCUMENT ME!
     *
     * @param language DOCUMENT ME!
     */
    public void setLanguage(String language) {
        setObject("Language", language);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getLanguage() {
        return (String) getObject("Language");
    }

    /**
     * DOCUMENT ME!
     *
     * @param lyric DOCUMENT ME!
     */
    public void setLyric(String lyric) {
        setObject("Lyrics/Text", lyric);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getLyric() {
        return (String) getObject("Lyrics/Text");
    }

    /**
     * DOCUMENT ME!
     *
     * @param text DOCUMENT ME!
     */
    public void addLyric(String text) {
        setLyric(getLyric() + text);
        ;
    }

    /**
     * DOCUMENT ME!
     *
     * @param line DOCUMENT ME!
     */
    public void addLyric(ObjectLyrics3Line line) {
        setLyric(getLyric() + line.writeString());
    }

    /**
     * DOCUMENT ME!
     */
    protected void setupObjectList() {
        objectList.add(new ObjectNumberHashMap("Text Encoding", 1));
        objectList.add(new ObjectStringHashMap("Language", 3));
        objectList.add(new ObjectStringNullTerminated("Description"));
        objectList.add(new ObjectStringSizeTerminated("Lyrics/Text"));
    }
}